package cn.smart.epic.common.constant.dictmap.factory;

import cn.smart.epic.common.constant.factory.ConstantFactory;
import cn.smart.epic.common.constant.factory.IConstantFactory;
import cn.smart.epic.common.exception.BizExceptionEnum;
import cn.smart.epic.common.exception.BussinessException;

import java.lang.reflect.Method;

/**
 * @Auther Uncle_Z
 * @date 2017/10/4 0:09
 * @Email:2545375@qq.com
 * @Descrition 字段的包装创建工厂
 * @since 1.0
 */

public class DictFieldWarpperFactory {

    public static Object createFieldWarpper(Object field,String methodName){
        IConstantFactory me = ConstantFactory.me();
        try{
            Method method =IConstantFactory.class.getMethod(methodName,field.getClass());
            Object result = method.invoke(me,field);
            return result;
        }catch (Exception e){
            try{
                Method method = IConstantFactory.class.getMethod(methodName,Integer.class);
                Object result = method.invoke(me, Integer.parseInt(field.toString()));
                return result;
            }catch (Exception e1){
                throw new BussinessException(BizExceptionEnum.ERROR_WRAPPER_FIELD);
            }
        }
    }
}
